package com.cskaoyan.servlet;

import com.cskaoyan.bean.vo.StatVo;
import com.cskaoyan.service.AdminStatService;
import com.cskaoyan.service.AdminStatServiceImpl;
import com.cskaoyan.util.ResponseUtil;
import lombok.SneakyThrows;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

//小组接口统计报表的实现

@WebServlet("/admin/stat/*")
public class AdminStatServlet extends WdBaseServlet {

    AdminStatService adminStatService= new  AdminStatServiceImpl();

    @SneakyThrows
    private void user(HttpServletRequest request, HttpServletResponse response){


        List<Map> rows= adminStatService.getGroupUserByTime();

         String[] columns=new String[]{"day", "users"};

        StatVo statVo = new StatVo();
        statVo.setColumns(columns);
        statVo.setRows(rows);
        ResponseUtil.responseOkJsonVo(response,statVo);

    }




    @SneakyThrows
    private void  order(HttpServletRequest request, HttpServletResponse response) {



        List<Map> rows = adminStatService.getAllOrderStat();
        String[] columns = new String[]{"day", "orders", "customers", "amount", "pcr"};
        StatVo statVo = new StatVo();
        statVo.setColumns(columns);
        statVo.setRows(rows);
        ResponseUtil.responseOkJsonVo(response,statVo);





    }
    @SneakyThrows
    private void  goods(HttpServletRequest request, HttpServletResponse response) {




        List<Map> rows = adminStatService.getAllOrderGoodsStat();
        String[] columns = new String[]{"day", "orders", "products", "amount"};
        StatVo statVo = new StatVo();
        statVo.setColumns(columns);
        statVo.setRows(rows);
        ResponseUtil.responseOkJsonVo(response,statVo);





    }

}
